package com.wisdom.benefit.jufa.im;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.wisdom.benefit.jufa.R;

import java.net.URISyntaxException;

import androidx.appcompat.app.AppCompatActivity;

public class TestActivity  {
//    private Context mContext;
//    private JWebSocketClient client;
//    private JWebSocketClientService.JWebSocketClientBinder binder;
//    private JWebSocketClientService jWebSClientService;;
//    private Button btn_send;
//    private ChatMessageReceiver chatMessageReceiver;
//    private static final String URL_FORMAT =
//            "intent://platformapi/startapp?saId=10000007&" +
//                    "clientVersion=3.7.0.0718&qrcode=https%3A%2F%2Fqr.alipay.com%2F{urlCode}%3F_s" +
//                    "%3Dweb-other&_t=1472443966571#Intent;" + "scheme=alipayqr;package=com.eg.android.AlipayGphone;end";
//    private ServiceConnection serviceConnection = new ServiceConnection() {
//        @Override
//        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
//            Log.e("MainActivity", "服务与活动成功绑定");
//            binder = (JWebSocketClientService.JWebSocketClientBinder) iBinder;
//            jWebSClientService = binder.getService();
//            client = jWebSClientService.client;
//        }
//
//        @Override
//        public void onServiceDisconnected(ComponentName componentName) {
//            Log.e("MainActivity", "服务与活动成功断开");
//        }
//    };
//
//    @Override
//    public void onPointerCaptureChanged(boolean hasCapture) {
//
//    }
//
//    @Override
//    public void onClick(View v) {
//
//    }
//
//    private class ChatMessageReceiver extends BroadcastReceiver {
//
//        @Override
//        public void onReceive(Context context, Intent intent) {
//           //TODO
//            String message = intent.getStringExtra("message");
//            Log.e("abc", message);
//        }
//    }
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_test);
//        mContext = TestActivity.this;
//        //启动服务
//        startJWebSClientService();
//        //绑定服务
//        bindService();
//        //注册广播
//        doRegisterReceiver();
//        btn_send = findViewById(R.id.btn);
//
//        btn_send.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                startAlipay(TestActivity.this,"fkx00630vsrcngr0p2oy518");
//            }
//        });
//    }
//
//    public boolean startAlipay(Activity activity, String urlCode) {
//        return startIntentUrl(activity, URL_FORMAT.replace("{urlCode}", urlCode));
//    }
//
//    public boolean startIntentUrl(Activity activity, String intentUrl) {
//        try {
//            Intent intent = Intent.parseUri(intentUrl, Intent.URI_INTENT_SCHEME);
//            activity.startActivity(intent);
//        } catch (URISyntaxException e) {
//            e.printStackTrace();
//        } catch (ActivityNotFoundException e) {
//            e.printStackTrace();
//        }
//        return false;
//    }
//
//    /**
//     * 绑定服务
//     */
//    private void bindService() {
//        Intent bindIntent = new Intent(mContext, JWebSocketClientService.class);
//        bindService(bindIntent, serviceConnection, BIND_AUTO_CREATE);
//    }
//
//    /**
//     * 启动服务（websocket客户端服务）
//     */
//    private void startJWebSClientService() {
//        Intent intent = new Intent(mContext, JWebSocketClientService.class);
//        startService(intent);
//    }
//
//    /**
//     * 动态注册广播
//     */
//    private void doRegisterReceiver() {
//        chatMessageReceiver = new ChatMessageReceiver();
//        IntentFilter filter = new IntentFilter("com.xch.servicecallback.content");
//        registerReceiver(chatMessageReceiver, filter);
//    }

}
